import 'package:flutter/material.dart';
import '../../utils/screen_util.dart';

class ConfirmDailog extends StatelessWidget {
  final String message;
  final void Function() onConfirm;
  final void Function() onCancel;
  final String cancelText;
  final String confirmText;
  final bool showCancel;

  const ConfirmDailog(
      {Key? key,
      required this.message,
      required this.onCancel,
      required this.onConfirm,
      this.cancelText = "cancel",
      this.confirmText = "ok",
      this.showCancel = true})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Container(
        width: ScreenUtil.screenWidth,
        height: ScreenUtil.screenHeight,
        color: Colors.transparent,
        child: Center(
          child: Container(
              width: 269,
              height: 160,
              padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
              decoration: const BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(20)),
              ),
              child: bodyBuild()),
        ),
      ),
    );
  }

  Widget bodyBuild() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      mainAxisSize: MainAxisSize.max,
      children: <Widget>[
        Expanded(
          flex: 1,
          child: Container(
            decoration: BoxDecoration(
                border: Border(
              bottom: BorderSide(
                  width: .5,
                  color: Colors.grey[200] ?? const Color(0x00eeeeee)),
            )),
            child: Center(
              child: Text(
                message,
                maxLines: 4,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ),
        ),
        Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            showCancel
                ? Expanded(
                    flex: 1,
                    child: GestureDetector(
                      child: Container(
                        color: Colors.white,
                        height: 40,
                        alignment: Alignment.center,
                        child: Text(
                          cancelText,
                          style:
                              const TextStyle(fontSize: 17, color: Colors.grey),
                        ),
                      ),
                      onTap: onCancel,
                    ),
                  )
                : const SizedBox(),
            Expanded(
              flex: 1,
              child: GestureDetector(
                child: Container(
                  color: Colors.white,
                  height: 40,
                  alignment: Alignment.center,
                  child: Text(
                    confirmText,
                    style: const TextStyle(fontSize: 17, color: Colors.blue),
                  ),
                ),
                onTap: onConfirm,
              ),
            )
          ],
        )
      ],
    );
  }
}
